package com.zhuanzhuan.hero.user.service.impl;

import com.zhuanzhuan.hero.social.interaction.enums.EAttentionRelationEnum;
import com.zhuanzhuan.hero.user.helper.HeroSocialHelper;
import com.zhuanzhuan.hero.user.pojo.bo.UserAttentionBO;
import com.zhuanzhuan.hero.user.service.IAttentionService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Collections;
import java.util.List;
import java.util.Objects;

/**
 * @ClassName AttentionServiceImpl
 * @Description
 * @Author hanjunjun
 * @Date 2024/7/9 14:26
 */
@Service
@Slf4j
public class AttentionServiceImpl implements IAttentionService {

    @Resource
    private HeroSocialHelper heroSocialHelper;

    @Override
    public boolean isAttention(Long fromUid, Long toUid) {
        List<UserAttentionBO> userAttentions =
            heroSocialHelper.queryserAttentions(fromUid, Collections.singletonList(toUid));
        UserAttentionBO userAttentionBO =
            userAttentions.stream().filter(userAttention -> userAttention.getToUid().equals(toUid)).findFirst()
                .orElse(null);
        if (Objects.isNull(userAttentionBO)) {
            return false;
        }

        return !EAttentionRelationEnum.NOT_ATTENTION.getCode().equals(userAttentionBO.getAttentionRelationCode());
    }
}
